package org.app.Controller;

import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.app.Entity.User;
import org.app.Entity.comm.Result;
import org.app.Service.Impl.UserService;
import org.app.Utils.SMSUtil;
import org.app.Utils.ValidateCodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/user")
@CrossOrigin("*")
public class UserController {
    @Resource
    private UserService userService;
    @Autowired
    private RedisTemplate redisTemplate;


    @PostMapping("/login")
    public Result<User> login(@RequestParam("c_phone") String c_phone,
                              @RequestParam("c_password") String c_password){
        return userService.Login(c_phone,c_password);
    }
    @PostMapping("/register")
    public Result<Integer> Register(@RequestBody User user){
        System.out.println("接收到的用户数据：" + user);
        return userService.Register(user);
    }
    @PutMapping("/updateInfo")
    public Result<Integer> updateUserInfo(@RequestBody User user){
        return userService.updateUserInfo(user);
    }

    @AllowAnonymous
    // 修改密码接口
    @PutMapping("/updatePassword")
    public Result<Integer> updatePassword(
            @RequestParam("username") String username,  // 用户名
            @RequestParam("phone") String phone,        // 手机号
            @RequestParam("new_password") String new_password,  // 新密码
            @RequestParam("token") String token
    ) {
        return userService.updateUserPassword(username, phone, new_password);
    }

}

